package com.hkts.naturalgas.organizational.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hkts.naturalgas.organizational.entity.HontPost;
import com.hkts.naturalgas.organizational.mapper.HontPostMapper;
import com.hkts.naturalgas.organizational.service.IHontPostService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yck
 * @since 2020-12-23
 */
@Service
@Transactional
public class HontPostServiceImpl extends ServiceImpl<HontPostMapper, HontPost> implements IHontPostService {


    @Autowired
    private HontPostMapper hontPostMapper;

    @Override
    public IPage<HontPost> selectPage(Page<HontPost> page, HontPost hontPost) {
        QueryWrapper<HontPost> query = Wrappers.query();
        QueryWrapper<HontPost> entityWrapper = getEntityWrapper(query, hontPost);
        return hontPostMapper.selectPage(page, entityWrapper);
    }


    @Override
    public List<HontPost> selectList(HontPost hontPost) {
        QueryWrapper<HontPost> query = Wrappers.query();
        QueryWrapper<HontPost> entityWrapper = getEntityWrapper(query, hontPost);
        return hontPostMapper.selectList(entityWrapper);
    }

    /**
     * 公共查询条件
     *
     * @param entityWrapper
     * @return
     */
    public QueryWrapper<HontPost> getEntityWrapper(QueryWrapper<HontPost> entityWrapper, HontPost hontPost) {
        //条件拼接
               /* if(StringUtils.isNotBlank(hontPost.getCreateTime())){
                entityWrapper.like(HontPost.CREATE_TIME,hontPost.getCreateTime());
                }*/
        if (StringUtils.isNotBlank(hontPost.getTitle())) {
            entityWrapper.like(HontPost.TITLE, hontPost.getTitle());
        }
        if (StringUtils.isNotBlank(hontPost.getId())) {
            entityWrapper.like(HontPost.ID, hontPost.getId());
        }
        if (StringUtils.isNotBlank(hontPost.getCreateBy())) {
            entityWrapper.like(HontPost.CREATE_BY, hontPost.getCreateBy());
        }
              /*  if(StringUtils.isNotBlank(hontPost.getDelFlag())){
                entityWrapper.like(HontPost.DEL_FLAG,hontPost.getDelFlag());
                }*/
        if (StringUtils.isNotBlank(hontPost.getUpdateBy())) {
            entityWrapper.like(HontPost.UPDATE_BY, hontPost.getUpdateBy());
        }
               /* if(StringUtils.isNotBlank(hontPost.getUpdateTime())){
                entityWrapper.like(HontPost.UPDATE_TIME,hontPost.getUpdateTime());
                }*/
        if (StringUtils.isNotBlank(hontPost.getFormId())) {
            entityWrapper.like(HontPost.FORM_ID, hontPost.getFormId());
        }
        return entityWrapper;
    }
}
